import { Dispatch } from "redux";
import * as actionType from '../constance'
import {
    getHotWordRequest,
    getHotCourseRequest,
    getSuggestionListRequest
} from '@/api/request'

export const setHotWrod=(data:[])=>({
    type:actionType.SET_HOTWORD,
    data
})
export const setSearchLoading=(data:boolean)=>({
    type:actionType.SET_SEARCH_LOADING,
    data
})

export const setHotCourse=(data:[])=>({
    type:actionType.SET_HOTCOURSE,
    data
})
export const setSuggestion=(data:[])=>({
    type:actionType.SET_SUGGESTION,
    data
})
export const getSuggestionAction=(keyword:string)=>{
    return (dispatch:Dispatch)=>{
        getSuggestionListRequest(keyword)
            .then(data=>{
                dispatch(setSuggestion(data.data.data))
            })
    }
}
export const getSearchAction=()=>{
    return (dispatch:Dispatch)=>{
        dispatch(setSearchLoading(true));
        return Promise.all([
            getHotWordRequest(),
            getHotCourseRequest()
        ]).then(([HotWordResult,HotCourseResult])=>{
            // console.log(HotCourseResult)
            dispatch(setHotWrod(HotWordResult.data.data))
            dispatch(setHotCourse(HotCourseResult.data.data))
        })
    }
}